package com.alibaba.travel.search.controller;

import com.alibaba.travel.common.utils.R;
import com.alibaba.travel.search.model.dto.ArticleSearchRequest;
import com.alibaba.travel.search.entity.EsArticle;
import com.alibaba.travel.search.service.ArticleSearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: where
 * @Date: 2023/03/09/8:36
 * @Description:
 */
@Api(tags = "文章搜索控制类")
@RestController
@RequestMapping("/search/article")
public class ArticleSearchController {
    @Autowired
    private ArticleSearchService articleSearchService;

    @ApiOperation(value = "通过ids上传文章")
    @PostMapping("/search")
    public R search(@RequestBody ArticleSearchRequest searchRequest) {
        List<EsArticle> list = articleSearchService.search(searchRequest);
        return R.ok().put("list", list);
    }

    @ApiOperation(value = "通过ids下架/删除文章")
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        articleSearchService.delete(ids);
        return R.ok();
    }


    @ApiOperation(value = "通过ids上传文章")
    @PostMapping("/upload")
    public R upload(Long[] ids) {
        articleSearchService.upload(ids);
        return R.ok();
    }

    /**
     * 在用户保存的时候可以进行
     */
    @ApiOperation(value = "通过文章详情信息上传文章")
    @PostMapping("/upload")
    public R upload(@RequestParam List<EsArticle> article) {
        articleSearchService.upload(article);
        return R.ok();
    }
}
